// mircoApp/new-auction/new_auction_withdraw/new_auction_withdraw.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: "",
    tag: "",
    can_withdraw_income: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
    })
    if (options.tag) {
      this.setData({
        tag: options.tag
      })
    }
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  tapAll() {
    if (this.data.can_withdraw_income == 0) {
      app.tips("提现失败，可提现金额为0")
      return;
    }
    this.setData({
      value: this.data.can_withdraw_income
    })
  },
  async save_withdrawTap() {
    let urlstr = app.getNetAddresss("plugin.new-auction.frontend.income.withdraw");
    if (this.data.tag == "balance") {
      urlstr = app.getNetAddresss("plugin.new-auction.frontend.money.withdraw");
    }
    let {
      data
    } = await app._postNetWork({
      url: urlstr,
      data: {
        amount: this.data.value
      }
    })
    app.tips(data.msg);
    if (data.result) {
      this.setData({
        value: ''
      })
      this.getData();
    }
  },
  async getData() {
    let urlstr = app.getNetAddresss("plugin.new-auction.frontend.income");
    if (this.data.tag == "balance") {
      urlstr = app.getNetAddresss("plugin.new-auction.frontend.money.memberInfo");
    }
    let {
      data
    } = await app._postNetWork({
      url: urlstr
    })
    if (data.result) {
      if (this.data.tag == 'balance') {
        this.data.can_withdraw_income = data.data.money;
      } else {
        this.data.can_withdraw_income = data.data.can_withdraw_income;
      }
      this.setData({
        can_withdraw_income: this.data.can_withdraw_income
      })
    } else {
      app.tips(data.msg)
    }
  }
})